this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i,n,a,r,l,o,s,d,u,c,m){"use strict";var g;var L=function(e){babelHelpers.inherits(i,e);babelHelpers.createClass(i,null,[{key:"isListField",value:function e(i){return t.Type.isArray(i.items)}}]);function i(e){var t;babelHelpers.classCallCheck(this,i);t=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(i).call(this,e));t.setEventNamespace("BX.Landing.UI.Field.DefaultValueField");t.subscribeFromOptions(a.fetchEventsFromOptions(e));t.onSelectFieldButtonClick=t.onSelectFieldButtonClick.bind(babelHelpers.assertThisInitialized(t));t.onItemRemove=t.onItemRemove.bind(babelHelpers.assertThisInitialized(t));t.onDragEnd=t.onDragEnd.bind(babelHelpers.assertThisInitialized(t));t.onFormChange=t.onFormChange.bind(babelHelpers.assertThisInitialized(t));t.items=[];t.actionPanel=new c.ActionPanel({renderTo:t.layout,left:[{id:"selectField",text:l.Loc.getMessage("LANDING_DEFAULT_VALUE_ADD_FIELD"),onClick:t.onSelectFieldButtonClick}]});t.draggable=new r.Draggable({context:window.parent,container:t.getListContainer(),draggable:".landing-ui-component-list-item",dragElement:".landing-ui-button-icon-drag",type:r.Draggable.MOVE,offset:{y:-62}});t.draggable.subscribe("end",t.onDragEnd);t.options.items.forEach((function(e){var i=t.prepareItemOptions({id:"".concat(e.entityName,"_").concat(e.fieldName),value:e.value});if(i){t.addItem(i)}}));return t}babelHelpers.createClass(i,[{key:"prepareItemOptions",value:function e(n){var a=this;var r=this.getCrmFieldById(n.id);if(r){var o=function(){if(i.isListField(r)){var e=a.getFieldItems(r);var o=e.find((function(e){return e.ID===n.value}));if(o){return o.VALUE}if(t.Type.isArrayFilled(e)){return e[0].VALUE}return l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_DEFAULT_VALUE")}if(r.type==="checkbox"){if(t.Text.toBoolean(n.value)){return l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_CHECKBOX_YES")}return l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_CHECKBOX_NO")}if(t.Type.isStringFilled(n.value)){return n.value}return l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_DEFAULT_VALUE")}();var s=function(){var e=a.getCrmFieldCategoryById(r.entity_name);return"".concat(r.caption," \xb7 ").concat(e.CAPTION)}();return{field:r,value:n.value,displayedValue:o,displayedLabel:s}}return null}},{key:"getListContainer",value:function e(){return this.cache.remember("listContainer",(function(){return t.Tag.render(g||(g=babelHelpers.taggedTemplateLiteral(['<div class="landing-ui-field-defaultvalue-list-container"></div>'])))}))}},{key:"createInput",value:function e(){return this.getListContainer()}},{key:"getCrmFieldById",value:function e(t){return Object.values(this.options.crmFields).reduce((function(e,t){return[].concat(babelHelpers.toConsumableArray(e),babelHelpers.toConsumableArray(t.FIELDS))}),[]).find((function(e){return e.name===t}))}},{key:"getCrmFieldCategoryById",value:function e(t){return this.options.crmFields[t]}},{key:"addItem",value:function e(t){this.items.push(new o.ListItem({id:t.field.name,title:t.displayedLabel,description:t.displayedValue,draggable:true,editable:true,removable:true,appendTo:this.getListContainer(),onRemove:this.onItemRemove,onFormChange:this.onFormChange,form:this.createItemForm(t)}))}},{key:"getItemById",value:function e(t){return this.items.find((function(e){return e.options.id===t}))}},{key:"onItemRemove",value:function e(t){this.items=this.items.filter((function(e){return e!==t.getTarget()}));this.emit("onChange",{skipPrepare:true})}},{key:"onFormChange",value:function e(t){var i=t.getTarget().getValue();var n=this.getItemById(i.name);var a=this.prepareItemOptions({id:i.name,value:i.label});if(n){n.setDescription(a.displayedValue)}this.emit("onChange",{skipPrepare:true})}},{key:"onDragEnd",value:function e(){var i=this;setTimeout((function(){i.items=babelHelpers.toConsumableArray(i.getListContainer().children).map((function(e){var n=t.Dom.attr(e,"data-id");return i.items.find((function(e){return e.options.id===n}))}));i.emit("onChange",{skipPrepare:true})}))}},{key:"getValue",value:function e(){var t=this;return this.items.map((function(e){var i=e.getValue();var n=t.getCrmFieldById(i.name);return{entityName:n.entity_name,fieldName:n.entity_field_name,value:i.value}}))}},{key:"onFieldsSelect",value:function e(t){var i=this;t.forEach((function(e){i.addItem(i.prepareItemOptions({id:e}))}));this.emit("onChange",{skipPrepare:true})}},{key:"getAllowedCategories",value:function e(){var i=this.options.formOptions.document.scheme;var n=this.options.dictionary.document.schemes.find((function(e){return String(i)===String(e.id)}));if(t.Type.isPlainObject(n)){return t.Runtime.clone(n.entities)}return[]}},{key:"onSelectFieldButtonClick",value:function e(t){var i=this;t.preventDefault();d.FieldsPanel.getInstance({isLeadEnabled:this.options.isLeadEnabled}).show({isLeadEnabled:this.options.isLeadEnabled,allowedCategories:this.getAllowedCategories(),allowedTypes:["string","list","enumeration","checkbox","boolean","radio","text","integer","double","date","datetime","typed_string"]}).then((function(e){i.options.crmFields=d.FieldsPanel.getInstance().getOriginalCrmFields();i.onFieldsSelect(e)}))}},{key:"getFieldItems",value:function e(i){if(i.entity_field_name==="STAGE_ID"){if(t.Type.isPlainObject(this.options.formOptions.document)&&t.Type.isPlainObject(this.options.formOptions.document.deal)){var n=t.Text.toNumber(this.options.formOptions.document.deal.category);if(n>0){return i.itemsByCategory[n]}}}return i.items}},{key:"createItemForm",value:function e(){var t=this;var a=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var r=new u.FormSettingsForm({serializeModifier:function e(i){if(a.field.type==="list"||a.field.type==="checkbox"||a.field.type==="bool"){var n=t.getFieldItems(r.fields[0]).find((function(e){return e.value===i.value}));if(n){i.label=n.name}}else{i.label=i.value}return i}});if(i.isListField(a.field)){r.addField(new BX.Landing.UI.Field.Dropdown({selector:"value",title:l.Loc.getMessage("LANDING_FORM_SETTINGS_DEFAULT_VALUE_VALUE_FIELD_TITLE"),content:a.value,items:this.getFieldItems(a.field).map((function(e){return{name:e.VALUE,value:e.ID}}))}));return r}if(a.field.type==="bool"||a.field.type==="checkbox"){r.addField(new BX.Landing.UI.Field.Dropdown({selector:"value",title:l.Loc.getMessage("LANDING_FORM_SETTINGS_DEFAULT_VALUE_VALUE_FIELD_TITLE"),content:a.value,items:[{name:l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_CHECKBOX_NO"),value:"N"},{name:l.Loc.getMessage("LANDING_DEFAULT_VALUE_FIELD_CHECKBOX_YES"),value:"Y"}]}));return r}if(a.field.type==="date"||a.field.type==="datetime"){r.addField(new n.DateTimeField({selector:"value",title:l.Loc.getMessage("LANDING_FORM_SETTINGS_DEFAULT_VALUE_VALUE_FIELD_TITLE"),time:a.field.type==="datetime",content:a.value||""}));return r}r.addField(new m.VariablesField({selector:"value",title:l.Loc.getMessage("LANDING_FORM_SETTINGS_DEFAULT_VALUE_VALUE_FIELD_TITLE"),variables:this.options.personalizationVariables,content:a.value||""}));return r}}]);return i}(i.BaseField);e.DefaultValueField=L})(this.BX.Landing.UI.Field=this.BX.Landing.UI.Field||{},BX,BX.Landing.UI.Field,BX.Landing.Ui.Field,BX.Landing.UI.Component,BX.UI.DragAndDrop,BX.Landing,BX.Landing.UI.Component,BX.Event,BX.Landing.UI.Panel,BX.Landing.UI.Form,BX.Landing.UI.Component,BX.Landing.UI.Field);
//# sourceMappingURL=defaultvaluefield.bundle.map.js